package com.googlecode.garbagecan.commons.clistudy.mycli;

import java.io.PrintWriter;
import java.io.StringWriter;

import org.apache.commons.cli.HelpFormatter;

public class HelpCommand implements Command {

	public String execute() {
		StringWriter sw = new StringWriter();
		PrintWriter pw = new PrintWriter(sw);
		
		String cmd = "xxx";
		CommandParser parser = new CommandParser();
		HelpFormatter formatter = new HelpFormatter();
		formatter.setSyntaxPrefix("Usage: ");
		formatter.printHelp(pw, 80, cmd, "Options:", parser.getOptions(), 2, 4, "", true);
		StringBuffer sb = new StringBuffer();
		sb.append("\n");
		sb.append(sw.getBuffer());
		sb.append("\n");
		sb.append("Examples:").append("\n");
		sb.append("  ").append(cmd).append(" start      Start server").append("\n");
		sb.append("  ").append(cmd).append(" stop       Stop server").append("\n");
		sb.append("  ").append(cmd).append(" -v         print the version information and exit").append("\n");
		sb.append("");
		System.out.println(sb.toString());
		return CMD_SUCCESS;
	}

}
